local sk__yongjie = fk.CreateSkill {

  name = "sk__yongjie",

  tags = {  },

}



sk__yongjie:addEffect(fk.EventPhaseStart, {
  name = "sk__yongjie",
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__yongjie.name) and player.phase == Player.Finish and
      table.find(player.room:getOtherPlayers(player), function (p)
        return #player.room.logic:getActualDamageEvents(1, function(e)
          local damage = e.data
          return damage.from == p and damage.to == player
        end, Player.HistoryGame) > 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player), function (p)
      return #room.logic:getActualDamageEvents(1, function(e)
        local damage = e.data
        return damage.from == p and damage.to == player
      end, Player.HistoryGame) > 0
    end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 999, "#sk__yongjie-choose", sk__yongjie.name, true)
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos=table.map(event:getCostData(self).tos,Util.Id2PlayerMapper)
    room:sortByAction(tos)
    local targets = tos
    for _, p in ipairs(targets) do
      if not p.dead then
        local n = #room.logic:getActualDamageEvents(999, function(e)
          local damage = e.data
          return damage.from == p and damage.to == player
        end, Player.HistoryGame)
        if #room:askForDiscard(p, n, n, true, sk__yongjie.name, true, nil, "#sk__yongjie-discard:::"..n) < n then
          room:changeMaxHp(p, -1)
        end
      end
    end
  end,
})

return sk__yongjie